{extend name="tpl/site_0/xdd/pc/public/layout.html" /}
{block name='title'}订单完成{$webConfig.WEBNAME}{/block}
{block name='head'}
<link rel="stylesheet" href="/public/plugins/tips/css/darktooltip.css">
{/block}
{block name='body'}
{include file="tpl/site_0/xdd/pc/public/head2.html"/}
<div class="header mainbox">
    <div class="logo lf">
        <a href="/"><img src="{$webConfig.LOGO}" width="315" height="65" /></a>
    </div>
    <div class="statusbox rf">
        <dl>
            <dd class="active">
                <span class="iconfont icon-gouwuche"></span>
                <div class="text">
                    查看购物车
                </div>
            </dd>
            <dd class="active">
                <span class="iconfont icon-querendingdan1"></span>
                <div class="text">
                    确认订单信息
                </div>
            </dd>
            <dd class="active">
                <span class="iconfont icon-querendingdan"></span>
                <div class="text">成功提交订单</div>
            </dd>
        </dl>
    </div>
</div>
<div class="shoppingcar-main">
    <div class="mainbox">
        <div class="order-title">
            订单信息
        </div>
        <div class="orderinfo">
            <div class="order-number">
                <span class="iconfont icon-queren"></span>
                <h2>订单提交成功！<span>订单编号：{$orderInfo.order_sn}</span></h2>
            </div>
            <div class="order-desc">
                <div class="order-row">
                    <h2>商品信息</h2>
                    <div class="info">
                        商品名字:{$orderInfo.goods_name}保证金
                    </div>
                    <div class="info">
                        商品总价:{$orderInfo.margin}元
                    </div>
                </div>
                <form method="post" id="payForm">
                    <input type="hidden" name="openid" value="{$Request.param.openid}" />
                    <input type="hidden" name="device" id="device" value="{$device}" />
                    <input type="hidden" name="site_id" value="{$orderInfo.site_id}" />
                    <input type="hidden" name="order_type" id="orderType" value="groupbuy_cart" />
                    <input type="hidden" name="order_sn" value="{$orderInfo.order_sn}" />
                    <input type="hidden" name="pay_code" value=""/>
                    <div class="order-row" style="padding:10px 0;">
                        <h2>支付信息</h2>
                        <div class="pay-type">
                            {volist name="payment" id="vo"}
                            <a href="javascript:;" onclick="setPay(this)" data-code="{$vo.pay_code}">
                                {eq name="vo.pay_code" value="alipay"}<i class="iconfont icon-alipay"></i>{/eq}
                                {eq name="vo.pay_code" value="wxpay"}<i class="iconfont icon-weixinzhifu"></i>{/eq}
                                {eq name="vo.pay_code" value="userpay"}<i class="iconfont icon-yue3"></i>{/eq}
                                {eq name="vo.pay_code" value="delivery"}<i class="iconfont icon-huoche"></i>{/eq}
                                {eq name="vo.pay_code" value="line"}<i class="iconfont icon-qianbao"></i>{/eq}
                                {$vo.pay_name}</a>
                            {/volist}
                        </div>
                    </div>
                    <div class="order-row" style="padding:30px;text-align:center;">
                        <a href="javascript:;" class="pay-btn" onclick="doPay(this);">立即支付</a>
                        <a href="{:url('home/Order/index')}" class="order-btn">订单中心</a>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{include file="tpl/site_0/xdd/pc/public/foot.html"/}
{/block}
{block name='js'}
<script src="/public/plugins/jquery.min.js"></script>
<script src="/public/plugins/tips/js/jquery.darktooltip.js"></script>
<script src="/public/plugins/tips/js/examples.js"></script>
<script type="text/javascript" src="/public/plugins/timedown/jquery.yomi.js" ></script>
<script>
    function setPay(obj) {
        var payCode=$(obj).data('code');
        $("input[name='pay_code']").val(payCode);
        $(obj).addClass('active').siblings().removeClass('active');
    }
    var device = $('#device').val();
    function doPay(obj) {
        var orderPrice = "{$orderInfo.margin}";
        var payCode = $("input[name='pay_code']").val();
        //余额支付 货到付款 线下付款
        if(payCode=='userpay' || payCode=='delivery' || payCode=='line'){
            $.post("{:url('home/Order/userpay')}",$('#payForm').serialize(),function(res){
                if(res.code==1){
                    location.href="{:url('home/Order/index')}";
                }else{
                    alert(res.msg);
                }
            });
        }
        //支付宝支付
        if(payCode=='alipay'){
            $('#payForm').attr('action',"{:url('plus/Alipay/pay')}");
            $('#payForm').submit();
            return false;
        }
        //微信支付
        if(payCode=='wxpay'){
            {eq name="device" value="3"}
            callpay();
            {else/}
            $.post("{:url('plus/Wxpay/pay')}",$('#payForm').serialize(),function(res){
                if(res.code==1){
                    var url="{:url('plus/Help/qrcode')}?qtext="+res.data;
                    var html = '<img src="'+url+'" style="width:120px;height:120px;display:block;margin:30px auto;" /><div style="font-size:12px;color:#333;text-align:center;">请在5分钟之内完成。如超时请刷新页面重新支付！</div>';
                    layer.open({
                        type: 1,
                        title:'<i class="iconfont icon-weixinzhifu" style="color:#41b035"></i> 微信扫码支付',
                        skin: 'layui-layer-rim', //加上边框
                        area: ['400px', '300px'], //宽高
                        content: html
                    });
                }else{
                    alert(res.msg);
                }
            });
            {/eq}
        }
    }
    {eq name="device" value="3"}
    //调用微信JS api 支付
    function jsApiCall() {
        WeixinJSBridge.invoke('getBrandWCPayRequest', {$jsApiParameters}, function (res) {
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    location.href = "{:url('home/Order/index')}";
                    return false;
                } else {
                    if (res.err_msg == "get_brand_wcpay_request:cancel") {
                        location.href = "{:url('home/Order/index')}";
                    } else {
                        alert('错误代码：' + res.err_code + '<br/>错误描述：' + res.err_desc + '<br/>错误：' + res.err_msg);
                    }
                }
            }
        );
    }
    //微信支付
    function callpay() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', jsApiCall);
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        } else {
            jsApiCall();
        }
    }
    {/eq}
</script>
{/block}